<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="用户账号" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户账号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          v-model="queryParams.password"
          placeholder="请输入密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="教员ID" prop="teacherId">
        <el-input
          v-model="queryParams.teacherId"
          placeholder="请输入教员ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入用户邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phonenumber">
        <el-input
          v-model="queryParams.phonenumber"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择用户性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="头像地址" prop="avatar">
        <el-input
          v-model="queryParams.avatar"
          placeholder="请输入头像地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最后登录IP" prop="loginIp">
        <el-input
          v-model="queryParams.loginIp"
          placeholder="请输入最后登录IP"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最后登录时间" prop="loginDate">
        <el-input
          v-model="queryParams.loginDate"
          placeholder="请输入最后登录时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="等级" prop="grade">
        <el-select v-model="queryParams.grade" placeholder="请选择等级" clearable>
          <el-option
            v-for="dict in dict.type.user_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="分组" prop="grouping">
        <el-select v-model="queryParams.grouping" placeholder="请选择分组" clearable>
          <el-option
            v-for="dict in dict.type.user_grouping"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="推荐人" prop="reference">
        <el-input
          v-model="queryParams.reference"
          placeholder="请输入推荐人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="余额" prop="balance">
        <el-input
          v-model="queryParams.balance"
          placeholder="请输入余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="积分" prop="integral">
        <el-input
          v-model="queryParams.integral"
          placeholder="请输入积分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="${comment}" prop="remark2">
        <el-input
          v-model="queryParams.remark2"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark3">
        <el-input
          v-model="queryParams.remark3"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark4">
        <el-input
          v-model="queryParams.remark4"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark5">
        <el-input
          v-model="queryParams.remark5"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark6">
        <el-input
          v-model="queryParams.remark6"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark7">
        <el-input
          v-model="queryParams.remark7"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
     <!-- <el-form-item label="${comment}" prop="remark8">
        <el-input
          v-model="queryParams.remark8"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark9">
        <el-input
          v-model="queryParams.remark9"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="${comment}" prop="remark10">
        <el-input
          v-model="queryParams.remark10"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['platformusers:platformusers:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['platformusers:platformusers:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['platformusers:platformusers:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['platformusers:platformusers:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="platformusersList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户账号" align="center" prop="userName" />
      <el-table-column label="密码" align="center" prop="password" />
      <el-table-column label="用户昵称" align="center" prop="nickName" />
      <el-table-column label="教员ID" align="center" prop="teacherId" />
      <el-table-column label="用户类型" align="center" prop="userType" />
      <el-table-column label="用户邮箱" align="center" prop="email" />
      <el-table-column label="手机号码" align="center" prop="phonenumber" />
      <el-table-column label="用户性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="头像地址" align="center" prop="avatar" />
      <el-table-column label="帐号状态" align="center" prop="status" />
      <el-table-column label="最后登录IP" align="center" prop="loginIp" />
      <el-table-column label="最后登录时间" align="center" prop="loginDate" width="160"/>
      <el-table-column label="等级" align="center" prop="grade">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_level" :value="scope.row.grade"/>
        </template>
      </el-table-column>
      <el-table-column label="分组" align="center" prop="grouping">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_grouping" :value="scope.row.grouping"/>
        </template>
      </el-table-column>
      <el-table-column label="推荐人" align="center" prop="reference" />
      <el-table-column label="余额" align="center" prop="balance" />
      <el-table-column label="积分" align="center" prop="integral" />
      <!-- <el-table-column label="备注" align="center" prop="remark1" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark2" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark3" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark4" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark5" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark6" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark7" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark8" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark9" /> -->
      <!-- <el-table-column label="${comment}" align="center" prop="remark10" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['platformusers:platformusers:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['platformusers:platformusers:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改平台用户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户账号" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户账号" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="用户昵称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入用户昵称" />
        </el-form-item>
        <el-form-item label="教员ID(当申请教员时，有这个ID)" prop="teacherId">
          <el-input v-model="form.teacherId" placeholder="请输入教员ID(当申请教员时，有这个ID)" />
        </el-form-item>
        <el-form-item label="用户邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入用户邮箱" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phonenumber">
          <el-input v-model="form.phonenumber" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="用户性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择用户性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="头像地址" prop="avatar">
          <el-input v-model="form.avatar" placeholder="请输入头像地址" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="最后登录IP" prop="loginIp">
          <el-input v-model="form.loginIp" placeholder="请输入最后登录IP" />
        </el-form-item>
        <el-form-item label="最后登录时间" prop="loginDate">
          <el-input v-model="form.loginDate" placeholder="请输入最后登录时间" />
        </el-form-item>
        <el-form-item label="等级" prop="grade">
          <el-select v-model="form.grade" placeholder="请选择等级">
            <el-option
              v-for="dict in dict.type.user_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分组" prop="grouping">
          <el-select v-model="form.grouping" placeholder="请选择分组">
            <el-option
              v-for="dict in dict.type.user_grouping"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="推荐人" prop="reference">
          <el-input v-model="form.reference" placeholder="请输入推荐人" />
        </el-form-item>
        <el-form-item label="余额" prop="balance">
          <el-input v-model="form.balance" placeholder="请输入余额" />
        </el-form-item>
        <el-form-item label="积分" prop="integral">
          <el-input v-model="form.integral" placeholder="请输入积分" />
        </el-form-item>
        <el-form-item label="备注" prop="remark1">
          <el-input v-model="form.remark1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="${comment}" prop="remark2">
          <el-input v-model="form.remark2" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="remark3">
          <el-input v-model="form.remark3" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="remark4">
          <el-input v-model="form.remark4" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="remark5">
          <el-input v-model="form.remark5" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="remark6">
          <el-input v-model="form.remark6" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="remark7">
          <el-input v-model="form.remark7" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="remark8">
          <el-input v-model="form.remark8" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="remark9">
          <el-input v-model="form.remark9" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="remark10">
          <el-input v-model="form.remark10" placeholder="请输入${comment}" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPlatformusers, getPlatformusers, delPlatformusers, addPlatformusers, updatePlatformusers } from "@/api/platformusers/platformusers";

export default {
  name: "Platformusers",
  dicts: ['sys_user_sex', 'user_level', 'user_grouping'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 平台用户信息表格数据
      platformusersList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        password: null,
        nickName: null,
        teacherId: null,
        userType: null,
        email: null,
        phonenumber: null,
        sex: null,
        avatar: null,
        status: null,
        loginIp: null,
        loginDate: null,
        grade: null,
        grouping: null,
        reference: null,
        balance: null,
        integral: null,
        remark1: null,
        remark2: null,
        remark3: null,
        remark4: null,
        remark5: null,
        remark6: null,
        remark7: null,
        remark8: null,
        remark9: null,
        remark10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "用户账号不能为空", trigger: "blur" }
        ],
        nickName: [
          { required: true, message: "用户昵称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询平台用户信息列表 */
    getList() {
      this.loading = true;
      listPlatformusers(this.queryParams).then(response => {
        this.platformusersList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId: null,
        userName: null,
        password: null,
        nickName: null,
        teacherId: null,
        userType: null,
        email: null,
        phonenumber: null,
        sex: null,
        avatar: null,
        status: null,
        delFlag: null,
        loginIp: null,
        loginDate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        grade: null,
        grouping: null,
        reference: null,
        balance: null,
        integral: null,
        remark1: null,
        remark2: null,
        remark3: null,
        remark4: null,
        remark5: null,
        remark6: null,
        remark7: null,
        remark8: null,
        remark9: null,
        remark10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加平台用户信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const userId = row.userId || this.ids
      getPlatformusers(userId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改平台用户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.userId != null) {
            updatePlatformusers(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlatformusers(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userIds = row.userId || this.ids;
      this.$modal.confirm('是否确认删除平台用户信息编号为"' + userIds + '"的数据项？').then(function() {
        return delPlatformusers(userIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('platformusers/platformusers/export', {
        ...this.queryParams
      }, `platformusers_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
